<template>
	<view class="container">
		<view class="top">
			<span @click="goback"><</span>
			<span>考试列表</span>
		</view>
		<view class="content" v-for="(item,index) in list " :key="item.id">
			<div class="tp">
				<p class="p">
					<span>{{item.title}}</span>
					<span>时长:{{item.expire}}</span>
				</p>
				<p class="pp">
					<span>题目总数:{{item.question_count}}</span>
					<span>总分数:{{item.total_score}}</span>
					<span>及格分数:{{item.pass_score}}</span>
				</p>
			</div>
			<view class="one">
				<button v-show="!flag">参加考试</button>
				<button v-show="flag">你考过了</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {getKaoshi} from "@/api/kaoshi.js"
	export default {
		data() {
			return {
				list:[],
				flag:false,
				query:{
					page:1,
					limit:10,
				},
				total:0,
				isloading:false,
			};
		},
		onLoad: function (options) {
			this.getkaoshilist()
			setTimeout(function () {
				console.log('start pulldown');
			}, 1000);
				uni.startPullDownRefresh();
			},
			onPullDownRefresh() {
				console.log('refresh');
				setTimeout(function () {
					uni.stopPullDownRefresh();
				}, 1000);
			},
		//上拉加载
		onReachBottom() {
			if(this.query.page<this.total){
				this.query.page++;
				this.getkaoshilist()
			}
				
		},
		methods:{
			//获取数据
			getkaoshilist(){
				getKaoshi(this.query).then(res=>{
					this.isloading=true;
					console.log(res);
					this.list=[...this.list,...res.data.rows]
					this.total=res.data.count
				})
				this.isloading=false;
			},
			//返回上一级
			goback(){
				uni.switchTab({
					url:"/pages/index/index"
				})
			}
		}
	}
</script>

<style lang="scss">
.container{
		background-color: #f5f5f3;
}
.top{
	width: 100%;
	height: 100rpx;
	display: flex;
	align-items: center;
	font-weight: bold;
	background-color: #fff;
	:nth-child(1){
		margin-left: 30rpx;
		font-size: 50rpx;
	}
	:nth-child(2){
		margin-left: 260rpx;
	}
}
.content{
	background-color: #fff;
	width: 100%;
	height: 300rpx;
	margin-top: 30rpx;
	.tp{
		border-bottom: 2rpx solid #ccc;
		padding: 24rpx;
		.p{
			display: flex;
			justify-content: space-between;
			:nth-child(1){
				font-weight: bold;
			}
			:nth-child(2){
				font-size: 20rpx;
				color: red;
			}
		}
		.pp{
			margin-top: 60rpx;
			:nth-child(2){
				padding-left: 40rpx;
			}
			:nth-child(3){
				padding-left: 40rpx;
			}
		}
	}
	.one{
		
		button{
			width: 200rpx;
			height: 90rpx;
			background-color: #5ccc86;
			float: right;
			margin-top: 8rpx;
			color: #fff;
			margin-right: 20rpx;
		}
	}
}
</style>
